<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="">
    <meta http-equiv="x-dns-prefetch-control" content="on">

    <title>首页</title>
    <link href="../css/css.css" rel="stylesheet" type="text/css">
    <script src="../js/jquery-v1.11.2.min.js"></script>
    <script src="../js/common.js"></script>
    <script src="../js/driver.js"></script>
    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.4&key=4082cc7cea44a1f8c926676ce9508fac&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.Geocoder"></script>
</head>
<body>
<section class="slider_inner">
    <div class="slider_dot">
        <div class="dot_checked w_checked"></div>
        <div class="dot_none w_none"></div>
        <div class="dot_none w_none"></div>
        <div class="dot_none w_none"></div>
        <div class="dot_none w_none"></div>
    </div>
    <div class="slider_item"><img src="../img/timg2.png"/></div>
</section>
<section class="pall15" style="overflow: hidden;">
    <div class="home_button mr4p" onclick="bid()">
        <label class="hometext">抢单</label>
        <i class="iconfont home_ico">&#xe70f;</i>
    </div>
    <div class="home_button" onclick="order()">
        <label class="hometext">我的订单</label>
        <i class="iconfont home_ico">&#xe710;</i>
    </div>
    <div class="home_button mr4p" id="workStatusDiv">
        <label class="hometext">开始接单</label>
        <i class="iconfont home_ico">&#xe712;</i>
    </div>
    <div class="home_button" onclick="newOrder()">
        <label class="hometext">一键下单</label>
        <label class="tel"></label>
        <i class="iconfont home_ico">&#xe711;</i>
    </div>
</section>
<form id="orderForm" name="orderForm" method="post">
     <input type="hidden" id="vehiclePriceId" name="vehiclePriceId" value=""/>
     <input type="hidden" id="bookDate" name="bookDate" value=""/>
     <input type="hidden" id="consignDesc" name="consignDesc" value=""/>
     <input type="hidden" id="consignName" name="consignName" value=""/>
     <input type="hidden" id="consignMobile" name="consignMobile" value=""/>
     <input type="hidden" id="callType" name="callType" value="NOW"/>
     <input type="hidden" id="addrType" name="addrType" value=""/>
     <input type="hidden" id="waybillRquirement10" name="waybillRquirement10" value=""/>
	 <input type="hidden" id="waybillRquirement20" name="waybillRquirement20" value=""/>
	 <input type="hidden" id="waybillRquirement30" name="waybillRquirement30" value="1"/>

	 <input type="hidden" id="startDistrictCode" name="startDistrictCode" value=""/>
	 <input type="hidden" id="startAddr" name="startAddr" value=""/>
	 <!--startPCD 起点 省市区-->
	 <input type="hidden" id="startPCD" name="startPCD" value=""/>
	 <!-- 起点经纬度 -->
	 <input type="hidden" id="startLocation" name="startLocation" value=""/>

	 <input type="hidden" id="endDistrictCode" name="endDistrictCode" value=""/>
	 <input type="hidden" id="endAddr" name="endAddr" value="目的地址"/>
	 <!--startPCD  省市区-->
	 <input type="hidden" id="endPCD" name="endPCD" value="上海市闵行区"/>
	 <!-- 终点经纬度 -->
	 <input type="hidden" id="endLocation" name="endLocation" value="121.339766,31.196099"/>

	  <!-- 第二终点参数 -->
	 <input type="hidden" id="endDistrictCode1" name="endDistrictCode1" value=""/>
	 <input type="hidden" id="endAddr1" name="endAddr1" value=""/>
	 <!--startPCD  省市区-->
	 <input type="hidden" id="endPCD1" name="endPCD1" value=""/>
	 <!-- 终点经纬度 -->
	 <input type="hidden" id="endLocation1" name="endLocation1" value=""/>

	 <!-- 第三终点参数 -->
	 <input type="hidden" id="endDistrictCode2" name="endDistrictCode2" value=""/>
	 <input type="hidden" id="endAddr2" name="endAddr2" value=""/>
	 <!--startPCD  省市区-->
	 <input type="hidden" id="endPCD2" name="endPCD2" value=""/>
	 <!-- 终点经纬度 -->
	 <input type="hidden" id="endLocation2" name="endLocation2" value=""/>
	 <input type="hidden" id="goodsRemark" name="goodsRemark" value=""/>
	 <input type="hidden" id="goodsType" name="goodsType" value="99"/>
	  <input type="hidden" id="goodsTypeName" name="goodsTypeName" value="其他"/>
	 <input type="hidden" id="consignNum" name="consignNum" value="1"/>
	 <input type="hidden" id="endAddrCount" name="endAddrCount" value="1"/>

	 <input type="hidden" id="planDistance" name="planDistance" value=""/>
	 <input type="hidden" id="planStartFee" name="planStartFee" value=""/>
	 <input type="hidden" id="planExceedFee" name="planExceedFee" value=""/>
	 <input type="hidden" id="planSpecialFee" name="planSpecialFee" value=""/>
	 <input type="hidden" id="planTotalFee" name="planTotalFee" value=""/>
	 <input type="hidden" id="specialFee10" name="specialFee10" value=""/>
	 <input type="hidden" id="specialFee20" name="specialFee20" value=""/>
	 <input type="hidden" id="driverUuid" name="driverUuid" />

	  <input type="hidden" id="startStreet" name="startStreet" />
	 <input type="hidden" id="startCross" name="startCross" />
	 <input type="hidden" id="startDoorNo" name="startDoorNo" />

	 <input type="hidden" id="endStreet" name="endStreet" value="目的地址"/>
	 <input type="hidden" id="endCross" name="endCross" />
	 <input type="hidden" id="endDoorNo" name="endDoorNo" />
	 <input type="hidden" id="acceptPersonMobile" name="acceptPersonMobile" />
	 <input type="hidden" id="acceptPersonName" name="acceptPersonName" />

	  <input type="hidden" id="endStreet1" name="endStreet1" />
	 <input type="hidden" id="endCross1" name="endCross1" />
	 <input type="hidden" id="endDoorNo1" name="endDoorNo1" />
	 <input type="hidden" id="acceptPersonMobile1" name="acceptPersonMobile1" />
	 <input type="hidden" id="acceptPersonName1" name="acceptPersonName1" />

	 <input type="hidden" id="endStreet2" name="endStreet2" />
	 <input type="hidden" id="endCross2" name="endCross2" />
	 <input type="hidden" id="endDoorNo2" name="endDoorNo2" />
	 <input type="hidden" id="acceptPersonMobile2" name="acceptPersonMobile2" />
	 <input type="hidden" id="acceptPersonName2" name="acceptPersonName2" />

	  <input type="hidden" id="planLoadTime" name="planLoadTime" />
	 <input type="hidden" id="planUnloadTime" name="planUnloadTime" />
	 <input type="hidden" id="planLoadFee" name="planLoadFee" />
	 <input type="hidden" id="planUnloadFee" name="planUnloadFee" />
	 <input type="hidden" id="planLowSpeedTime" name="planLowSpeedTime" />
	 <input type="hidden" id="planLowSpeedFee" name="planLowSpeedFee" />
</form>
<script type="text/javascript">
		var isGeocoded = 0;
		var isFullCar = "";
    $(function () {
        checkDriverTokenIndex();//token验证
        
        try{
        	delegate.initFirtLoad(getCookie("driverUuid"));
      	}catch(e){}

        var driverUuid=getCookie("driverUuid");
				$("#driverUuid").val(driverUuid);
				var callType="NOW";

				var url = _global.serverHost +"/driverOrder/inputOrder.htm";
				var driverUuid=getCookie("driverUuid");
				var data = {
					'callType':callType,
					'driverUuid':driverUuid
				};
				_callAjaxRequest(url, data, callBack);
				function callBack(data) {
					//alert(JSON.stringify(data));
					//cookie2Order();
					var trackList = data.trackList;
					var endAddrCount = 1;
					isFullCar = data.c3;
							
					var vehiclePriceId = $("#vehiclePriceId").val();
					console.log("=====vehiclePriceId=" + vehiclePriceId);
					for (var i = 0; i < trackList.length; i++) {
						if (data.vehicleType == trackList[i].vehicleType) {
							$("#vehiclePriceId").val(trackList[i].id);
						}
					}
					var bookDate = $("#bookDate").val();
					//alert("=====bookDate=" + bookDate);
					//console.log("=====bookDate=" + bookDate);
					//alert("=====bookDate222222222=" + data.bookDateHHMM);
					$("#bookDate").val(data.bookDateHHMM);
				}

				$("#startDistrictCode").val(10);
				$("#startAddr").val("南陈路43号");
				$("#startPCD").val("上海市" + "上海市" + "宝山区");
				$("#startLocation").val("121.319308,31.240986");
				$("#startStreet").val("南陈路43号");

				quickBill();
				
				setTimeout("genWorkStatusInit()", 1000 );	

    });
    
    var initTishi = 0;
    
    function genWorkStatusInit(){
    	try{
	    	if(localStorage.getItem("driverInfo")){
		    	var driverInfo = eval("("+localStorage.getItem("driverInfo")+")");
		      //alert("==genWorkStatusInit=="+JSON.stringify(driverInfo));
		      var lockFlag = driverInfo.lockFlag;	
		    	var htmlStr="";
		    	if(lockFlag=="0"){
	    			$("#workStatusDiv").removeClass();
	          $("#workStatusDiv").addClass("home_button_stop mr4p");
	        	htmlStr='<label class="hometext" onclick="chgWorkStatus(1);">停止接单</label><i onclick="chgWorkStatus(1);" class="iconfont home_ico">&#xe719;</i>';
	        }else{
	        	try{
	        		if(initTishi == 0){
		        		delegate.playTishi();
		        		initTishi = 1;
	        		}
	        	}catch(e){
	        	}
	        	$("#workStatusDiv").removeClass();
	          $("#workStatusDiv").addClass("home_button mr4p");
	        	htmlStr='<label class="hometext" onclick="chgWorkStatus(0);">开始接单</label><i onclick="chgWorkStatus(0);" class="iconfont home_ico">&#xe712;</i>';
	        }
	        $("#workStatusDiv").html(htmlStr);
	      }else{
	      	setTimeout("genWorkStatusInit()", 2000 );	
	      }
	    }catch(e){
	    	alert(e);	
	    }
    }
    
    function bid() {
        //window.location.href = "../driver/bid/bid_list.html";
        delegate.bid();
    }
    function order() {
        //window.location.href = "../driver/order/order_list.html";
        delegate.order();
    }
    function newOrder() {
		//clearOrderCookie();
		//setCookie("callType","NOW");
		//window.location.href = "../driver/order/input_order_now.html";
		
		var update = confirm('您确定现在要一键下单吗？');
		
		if (update) {
		if(isGeocoded!=1){
			alert("位置获取中，请稍后！");
			return false;
		}
		if(isFullCar!='00'){
			alert("您现在不在空车状态，不能一键下单！");
			return false;	
		}
		$.ajax({
					type : 'POST',
					url : _global.serverHost + '/driverOrder/saveOrder.htm',
					data : $('#orderForm').serialize(),
					contentType : "application/x-www-form-urlencoded;charset=UTF-8",
					success : function(data) {
						if (data.outResult == '1') {
							//window.location.href = "./start_bid/goon_bid1.html?waybillId="+ data.waybillId;
							var urls = "driver/start_bid/goon_bid1.html?waybillId="+ data.waybillId;
							delegate.bill(urls);
						} else {
							alert(data.outResultReason);
						}
					}
				});
			}
		}
    function call(tel) {
        //delegate.call(tel);
        clearOrderCookie();
    		setCookie("callType","NOW");
    		delegate.bill();
        //window.location.href = "../driver/order/input_order_now.html";
    }
    function genWorkStatus(lockFlag){
    	var htmlStr="";
	
    	if(lockFlag=="0"){
    		try{
	      		delegate.playStartBid();
	    	}catch(e){
	    		alert(e);
	    	}
    		$("#workStatusDiv").removeClass();
            $("#workStatusDiv").addClass("home_button_stop mr4p");
        	htmlStr='<label class="hometext" onclick="chgWorkStatus(1);">停止接单</label><i onclick="chgWorkStatus(1);" class="iconfont home_ico">&#xe719;</i>';
        }else{
        	    		try{
	      		delegate.playEndBid();
	    	}catch(e){
	    		alert(e);
	    	}
        	$("#workStatusDiv").removeClass();
            $("#workStatusDiv").addClass("home_button mr4p");
        	htmlStr='<label class="hometext" onclick="chgWorkStatus(0);">开始接单</label><i onclick="chgWorkStatus(0);" class="iconfont home_ico">&#xe712;</i>';
        }
        $("#workStatusDiv").html(htmlStr);
    }
    function chgWorkStatus(lockFlag) {
    	var driverUuid=getCookie("driverUuid");
        $.ajax({
            type: 'POST',
            url: _global.serverHost + '/driver/chgLockFlag.htm',
            dataType: "json",
            data: { 'driverUuid': driverUuid,'lockFlag':lockFlag},
            success: function (data) {
                if (data.outResult == '1') {
                	console.log("===="+JSON.stringify(data));
                	genWorkStatus(data.lockFlag);
                } else {
                	alert(data.outResultReason);
                }
            }
        });
    }

    function quickBill() {
		var lnglatXY = [ 121.319308, 31.240986 ]; //已知点坐标
		//如果获取不到的地址的话，默认一个经纬度
		var llon = '121.319308';
		var llat = '31.240986';
		try {
			var positionStr = delegate.getCurrentLocation();
			//alert(positionStr);
			if (positionStr != undefined && positionStr != null) {
				if(positionStr.length == 12){
					setTimeout("quickBill()", 3000 );	
					return;
				}
				//'{lon=101,lat=102}'转化为'{lon:101,lat:102}'
				positionStr = positionStr.replace("=", ":").replace("=", ":");
				//string 转化为json
				var positionObj = eval('(' + positionStr + ')');
				//alert("positionObj="+JSON.stringify(positionObj));
				llon = positionObj.lon;
				llat = positionObj.lat;
//alert("positionObj.lon="+positionObj.lon);
				if (llon != undefined && llon != null && llon != '') {
					lnglatXY = [ llon, llat ];
				}
				//alert("lnglatXY.lon="+lnglatXY[0]);
			}
		} catch (e) {
			lnglatXY = [ 121.319308, 31.240986 ]; //已知点坐标
			console.log("delegate.getCurrentLocation()不能读取当前地址经纬度");
		}
		var geocoder = new AMap.Geocoder({
			radius : 1000,
			extensions : "all"
		});
		try{
			geocoder.getAddress(lnglatXY, function(status, result) {
				//alert(result.info);
				//alert("====="+status);
				if (status === 'complete' && result.info === 'OK') {
					geocoder_CallBack(result);
				}
			});
		}catch (e) {
			alert(e);
		}
		function geocoder_CallBack(result) {
			var a = result.regeocode.addressComponent;
			var aa = result.regeocode.pois;
			$("#startDistrictCode").val(a.adcode);
			$("#startAddr").val(aa[0].name);
			//$("#tipinput").val(aa[0].name);
			$("#startPCD").val(a.province + a.city + a.district);
			$("#startLocation").val(llon + ',' + llat);
			//$("#startAddrDesc").html(aa[0].name);
			//$("#startStreetDesc").html(a.street + a.streetNumber);
			$("#startStreet").val(a.street + a.streetNumber);
			//alert("====="+JSON.stringify(aa[0]));
			isGeocoded = 1;
		}
	}
</script>
</body>
</html>

<script>
	try{
		delegate.updatePhoneInfo();
	}catch(e){
			//alert(e);
	}
	
	try{
		var result = delegate.checkVersion();
    if (result != '0') {
        var update = confirm('有新版本，确定升级吗？');
        if (update) {
            delegate.updateApp();
        }
    }
	}catch(e){
			//alert(e);
	}
</script>